<template>
  <hierTree
    :data="data"
    v-bind="attrs"
    :ref="ref"
    @select="select"
    @add="add"
    @remove="remove"
    @menu="menu"
  ></hierTree>
</template>

<script>
export default {
  name: "pg-tree",
  components: {},
  inject: ["anc"],
  data() {
    return {
      ref: "deptTree",
      loading: false,
    };
  },
  props: {
    data: {
      default: () => {
        return [];
      },
    },
  },
  watch: {},
  computed: {
    attrs() {
      return {
        title: {
          "en-US": "AAA",
          "zh-CN": "部门",
        }[this.G_Locale],
        rootId: "root",
        nameId: "id",
        namePid: "parentId",
        nameTitle: "name",
        rootEnable: true,
        menuEnable: true,
        addEnable: true,
        removeEnable: true,
        menus: [
          {
            title: {
              "en-US": "add1",
              "zh-CN": "查看",
            }[this.G_Locale],
            disabled: false,
          },
          {
            title: {
              "en-US": "edit",
              "zh-CN": "编辑",
            }[this.G_Locale],
            disabled: false,
          },
        ],
      };
    },
  },
  created() {},
  mounted() {
    this.$nextTick(() => {
      this.$set(this.anc.vms, this.ref, this);
    });
  },
  methods: {
    select(item, data) {
      this.anc.deptTreeSelect(item, data);
    },
    add(item) {
      console.log(item);
      this.anc.handlCreateTree(item);
    },
    remove(item) {
      console.log(item);
      this.anc.handlRemoveTree(item);
    },
    menu(menu, item) {
      console.log(menu, item);
      if (menu.title == '编辑') { 
        this.anc.handlEditTree(item);
      } else {
        this.anc.handlDetailTree(item);
      }
    },
  },
};
</script>
<style scoped></style>
